package moddb;

import org.mortbay.jetty.security.*;

import java.io.IOException;
import java.security.Principal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import org.mortbay.jetty.Request;
import org.mortbay.log.Log;
import org.mortbay.resource.Resource;
import org.mortbay.util.Loader;


public class JDBCSHA1UserRealm extends JDBCUserRealm {
  
  public JDBCSHA1UserRealm(String realm, String prop) throws IOException,
                ClassNotFoundException,
                InstantiationException,
                IllegalAccessException
 {
    
    super(realm, prop);
  }
  
  public Principal authenticate(String username,
                                   Object credentials,
                                   Request request)
  {
    System.err.println("cred: " + credentials);
    
    try {
      return super.authenticate(username, AeSimpleSHA1.SHA1("SALTar" + (String)credentials), request);
    } catch (Exception e) {
      System.err.println("Warning, could not use SHA1");
      return super.authenticate(username, credentials, request);
    }
  }
  
}
